package com.kevin.mybatis.rocketmq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class SyncProducer {

    public static void main(String[] args) throws Exception {
        //创建一个producer
        DefaultMQProducer producer = new
                DefaultMQProducer("pg");
        // Specify name server addresses.
        producer.setNamesrvAddr("124.222.229.114:9876");
        producer.setVipChannelEnabled(false);

        // 设置当发送失败的时候重试的次数  默认两次
        producer.setRetryTimesWhenSendAsyncFailed(3);
        // 设置发送超时时间 默认3秒
        producer.setSendMsgTimeout(10000);
        //Launch the instance.
        producer.start();


        for (int i = 0; i < 100; i++) {
            byte[] body = ("Hi," + i).getBytes();
            Message msg = new Message("someTopic", body);
            SendResult send = producer.send(msg);
            System.out.println(send);
        }
        //Shut down once the producer instance is not longer in use.
        producer.shutdown();
    }
}
